package com.hyh.controller;

import com.hyh.service.ToolsService;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.tools.Tool;

@RestController
public class ToolsController {

    private final ChatClient chatClient;
    public ToolsController(DeepSeekChatModel deepSeekChatModel,
                           ToolsService toolsService) {
        this.chatClient = ChatClient.builder(deepSeekChatModel)
                .defaultTools(toolsService)
                .defaultAdvisors(new SimpleLoggerAdvisor())
                .build();
    }

    @RequestMapping("/tool")
    public String tool(@RequestParam(value = "message",defaultValue = "讲一个笑话")
                       String message){
        return chatClient.prompt().user(message)
//                .tools()  // 也可以为单次对话配置
                .call().content();
    }
}
